package com.keshe.dao;

import com.keshe.domain.Room;
import com.keshe.util.DBUtil;

import java.util.List;

public class RoomDao {
    //插入房间信息
    public int insert(Room rm){
        String sql ="insert room values(?,?,?,?,?,?,?,?)";
        int count= DBUtil.update(sql,rm.getRoomid(),rm.getHousename(),rm.getHomeloc(),rm.getHousecoast(),rm.getHousesize(),rm.getHousesnull(),rm.getHousesclean(),rm.getHousesdesc());
        return count;
    }
    //显示房间信息
    public List<Room> select(){
        String sql="select * from room";
        List<Room> ri =DBUtil.query(sql,Room.class);
        return ri;
    }
    //根据id查询房间用于删除数据
    public List<Room> selectId(String roomid ){
        String sql="select * from room where roomid=?";
        List<Room> ri =DBUtil.query(sql,Room.class,roomid);
        return ri;
    }
    //根据房间名查询房间
    public List<Room> selectName(String housesname ){
        String sql="select * from room where housename=?";
        List<Room> ri =DBUtil.query(sql,Room.class,housesname);
        return ri;
    }
    //根据id删除数据
    public int delete(String id){
        String sql="delete from room where roomid=?";
        int count=DBUtil.update(sql,id);
        return count;
    }
    //根据id修改数据
    public int update(String id,String housename,String homeloc,int housecoast,String housesize,String housesnull,String housesclean,String housesdesc){
        String sql="update room set housename=?,homeloc=?,housecoast=?,housesize=?,housesnull=?,housesclean=?,housesdesc=? where roomid=?";
        int count= DBUtil.update(sql,housename,homeloc,housecoast,housesize,housesnull,housesclean,housesdesc,id);
        return count;
    }
    //根据id修改房间空闲状态
    public int updateId(String id,String housesnull){
        String sql="update room set housesnull=?where roomid=?";
        int count= DBUtil.update(sql,housesnull,id);
        return count;
    }
}
